# File: examples/Makefile (optional)
TOP_DIR := ..
include $(TOP_DIR)/buildcfg/toolscfg.mk
include $(TOP_DIR)/buildcfg/modulescfg.mk

# 编译器及参数设定
# ---------------------------------------------------------------------------
LOCAL_TARGET         ?= examples_app.out

LOCAL_SRC_DIR        := .
LOCAL_SRCS           := $(wildcard $(LOCAL_SRC_DIR)/*.c)
LOCAL_OBJS           := $(LOCAL_SRCS:$(LOCAL_SRC_DIR)/%.c=%.o)
LOCAL_DEPS           := $(LOCAL_OBJS:.o=.d)

LOCAL_CLEAN_FILES    += $(LOCAL_TARGET) $(LOCAL_OBJS) $(LOCAL_DEPS)

LOCAL_INCFLAGS       += -I$(TOP_DIR)/include/common
LOCAL_CXXFLAGS       += $(CXXFLAGS) -MMD -MP
LOCAL_LDFLAGS        += $(LDFLAGS) -L.
LOCAL_LIBS           += 
LOCAL_DEF_FLAGS      += $(GITFLAGS) -DBIN=\"EXAMPLE\"
# 输出模式控制
# ---------------------------------------------------------------------------
ifneq ($(V),1)
quiet = quiet_
Q = @
else
quiet =
Q =
endif

# 命令定义 (格式: quiet_cmd_<类型> + cmd_<类型>)
# ---------------------------------------------------------------------------
quiet_cmd_cc    = CC      $<
      cmd_cc    = $(CXX) $(LOCAL_DEF_FLAGS) $(LOCAL_CXXFLAGS) $(LOCAL_INCFLAGS) -c $< -o $@
   
quiet_cmd_ld    = LD      $@
      cmd_ld    = $(CXX) $^ -o $@ $(LOCAL_LDFLAGS) $(LOCAL_LIBS)

quiet_cmd_clean = CLEAN   $(LOCAL_CLEAN_FILES)
      cmd_clean = rm -f $(LOCAL_CLEAN_FILES)

# 通用命令执行函数 用法: $(call cmd,<命令类型>,<显示参数>)
# ---------------------------------------------------------------------------
cmd = $(Q)$(if $($(quiet)cmd_$(1)),\
    @printf "  %-8s%s\n" "$($(quiet)cmd_$(1))"; $(cmd_$(1)),\
    $(cmd_$(1)))

# 构建规则
# ---------------------------------------------------------------------------
all: $(LOCAL_TARGET)

$(LOCAL_TARGET): $(LOCAL_OBJS)
	$(call cmd,ld)

%.o: %.c
	$(call cmd,cc,$<)


# 包含自动生成的依赖
# ---------------------------------------------------------------------------
-include $(LOCAL_DEPS)

# clean
# ---------------------------------------------------------------------------
clean:
	$(call cmd,clean)

.PHONY: all clean

